package com.bishe.demo.modules.tourism.dao;

import com.bishe.demo.modules.tourism.entity.TourismImage;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
* @Description TourismImageDao
* @Author Lubb
* @Date 2021/3/30 11:10
*/
@Repository
@Mapper
public interface TourismImageDao {
    @Insert("insert into tourism_image(url) values(#{url})")
    @Options(useGeneratedKeys = true,keyColumn = "id",keyProperty = "id")
    void addTourismImage(TourismImage tourismImage);

    @Delete("delete from tourism_image where id = #{id}")
    void deleteTourismImageById(Integer id);

    @Delete("delete from tourism_image where id = (select image_id from tourism_route_image where route_id = #{routeId})")
    void deleteTourismImageByRouteId(Integer routeId);

    @Update("update tourism_image set url = #{url} where id = #{id}")
    void updateTourism(TourismImage tourismImage);

    @Select("select * from tourism_image as ti left join tourism_route_image as tri on " +
            "ti.id = tri.image_id where tri.route_id = #{routeId}")
    List<TourismImage> getTourismImagesByRouteId(Integer routeId);
}
